package jdbc.图书管理系统;
import jdbc.util.BaseDao;
import java.util.Scanner;
public class LibraryTwoVeactor {
    public static void main(String[] args) {
         Scanner dr=new Scanner(System.in);
         for (;;){
             System.out.println("---------------------");
             System.out.println("欢迎光临喵喵图书馆");
             System.out.println("请输入账号");
             String zh=dr.next();
             String select="select * from user;";
             user hao=BaseDao.executeDQL(select,user.class).get(1);
             if (hao.name.equals(zh)) {
                 System.out.println("请输入密码");
                 String mima=dr.next();
                 if (hao.mima.equals(mima)) {
                     System.out.println("恭喜你登陆成功!!!!");
                     System.out.println("本馆提供以下服务:");
                     System.out.println("1.借书");
                     System.out.println("2.还书");
                     System.out.println("3.退出");
                     System.out.println("请输入服务序号:");
                     int sL=dr.nextInt();
                     if (sL==1) {// TODO 借书
                         let(1);
                     } else if (sL==2) {// TODO 还书
                         let(2);
                     } else if (sL==3) {// TODO 书籍目录
                         let(3);
                     }else {
                         System.out.println("输入错误,请重新输入");
                     }
                 }else{
                     System.out.println("密码输入错误,请重新输入");
                 }
             }else{
                 System.out.println("无效账号,请注册");
             }
         }
    }
    public static void let( int choose){
        String sel="select * from book where id=?;";
         int w1=2301; math se1=BaseDao.executeDQL(sel, math.class,w1).get(1);
         int w2=2302; math se2=BaseDao.executeDQL(sel, math.class,w2).get(2);
         int w3=2303; math se3=BaseDao.executeDQL(sel, math.class,w3).get(3);
         int w4=2304; math se4=BaseDao.executeDQL(sel, math.class,w4).get(4);
         int w5=2305; math se5=BaseDao.executeDQL(sel, math.class,w5).get(5);
        System.out.println("--------------------------------------");
        System.out.println("现在有以下图书和剩余数量");
        System.out.println("书名      剩余数量");
        System.out.println("1.水浒传: "+se1.math);
        System.out.println("2.计算机基础: "+se2.math);
        System.out.println("3.数据库原理: "+se3.math);
        System.out.println("4.高等数学: "+se4.math);
        System.out.println("5.离散数学: "+se5.math);
        if (choose==1) {
            Scanner dr=new Scanner(System.in);
            System.out.println("请输入想要借的书的序号:");
            int Sl=dr.nextInt();
            System.out.println("请输入借书数量");
            int books=dr.nextInt();
            String update="update book set math=? where id=?";
            if (Sl ==1) {
               int math= se1.math-books;
                if (math <0) {
                    System.out.println("图书数量不足,借取失败");
                }else {
                    BaseDao.executeDML(update,math,w1);
                    System.out.println("借书成功");
                }
            }else if (Sl ==2) {
                int math= se2.math-books;
                if (math <0) {
                    System.out.println("图书数量不足,借取失败");
                }else {
                    BaseDao.executeDML(update,math,w2);
                    System.out.println("借书成功");
                }
            }else if (Sl ==3) {
                int math= se3.math-books;
                if (math <0) {
                    System.out.println("图书数量不足,借取失败");
                }else {
                    BaseDao.executeDML(update,math,w3);
                    System.out.println("借书成功");
                }
            }else if (Sl ==4) {
                int math= se4.math-books;
                if (math <0) {
                    System.out.println("图书数量不足,借取失败");
                }else {
                    BaseDao.executeDML(update,math,w4);
                    System.out.println("借书成功");
                }
            }else if (Sl ==5) {
                int math= se5.math-books;
                if (math <0) {
                    System.out.println("图书数量不足,借取失败");
                }else {
                    BaseDao.executeDML(update,math,w5);
                    System.out.println("借书成功");
                }
            }
        } else if (choose==2) {
            Scanner dr=new Scanner(System.in);
            System.out.println("请输入想要还的书的序号:");
            int Sl=dr.nextInt();
            System.out.println("请输入还书数量");
            int books=dr.nextInt();
            String update="update book set math=? where id=?";
            if (Sl ==1) {
                int math= se1.math+books;
                BaseDao.executeDML(update,math,w1);
            }else if (Sl ==2) {
                int math= se2.math+books;
                BaseDao.executeDML(update,math,w2);
            }else if (Sl ==3) {
                int math= se3.math+books;
                BaseDao.executeDML(update,math,w3);
            }else if (Sl ==4) {
                int math= se4.math+books;
                BaseDao.executeDML(update,math,w4);
            }else if (Sl ==5) {
                int math= se5.math+books;
                BaseDao.executeDML(update,math,w5);
            }
        } else if (choose==3) {
            System.exit(0);
        }
    }
}